local FruitMap = class("FruitMap");

function FruitMap:ctor(rowCount,colCount,space,itemWidth,itemHeight)
	self.m_rowCount = tonumber(rowCount) or 1;
	self.m_colCount = tonumber(colCount) or 1;
	self.m_space = tonumber(space) or 0;
	self.m_itemWidth = tonumber(itemWidth) or 1;
	self.m_itemHeight = tonumber(itemHeight) or 1;

	--print("FruitMap.."..itemWidth.."..."..itemHeight)
end

--矩阵大小
function FruitMap:getSize()
	if not (self.m_width or self.m_height) then 
		self.m_width = self.m_colCount*self.m_itemWidth + (self.m_colCount - 1)*self.m_space;
		self.m_height = self.m_rowCount*self.m_itemHeight + (self.m_rowCount - 1)*self.m_space;
	end 
	--print("FruitMap.....getSize.."..self.m_width.."..."..self.m_height);

	return {width = self.m_width,height = self.m_height};
end

--矩阵对齐方式
function FruitMap:getAlign()
	return display.CENTER;
end

--矩阵左下角起始位置
function FruitMap:getPos()
	if not (self.m_sx or self.m_sy) then
		local size = self:getSize();
		self.m_sx = (display.width - size.width)/2;
		self.m_sy = (display.height - size.height)/2;

		--print("FruitMap.....getPos.."..self.m_sx.."..."..self.m_sy);
	end 

	return cc.p(self.m_sx,self.m_sy);
end

--指定行列的item的位置
--row,col：行列；从下往上算行，从左往右算列
function FruitMap:getItemPos(row,col)
	local pos = self:getPos();
	local sx,sy = pos.x,pos.y;
	local px = sx + (col - 1)*(self.m_itemWidth + self.m_space) + self.m_itemWidth/2;
	local py = sy + (row - 1)*(self.m_itemHeight + self.m_space) + self.m_itemHeight/2;

	--print("FruitMap.....getItemPos.."..px.."..."..py);

	return cc.p(px,py); 
end 

return FruitMap;